package com.xsprite.managesys.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xsprite.managesys.bean.GMServer;
import com.xsprite.managesys.bean.Plat;
import com.xsprite.managesys.service.GMCommandManager;

import net.sf.json.JSONArray;

/**
 * Servlet implementation class GetGMServersServlet
 */
public class GetGMServersServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		super.service(req, resp);
		int platInt = Integer.parseInt(queryParam("plat"));
		Plat plat = Plat.getValueByOrdinal(platInt);
		List<GMServer> gmServers = GMCommandManager.getInstance().getGMServersByPlat(plat);
		JSONArray jsonArray = JSONArray.fromObject(gmServers);
		PrintWriter out = resp.getWriter();  
        out.write(jsonArray.toString());
	}
}
